from django.db import models
import time


# Create your models here.

# 会员等级
class Role(models.Model):
    name = models.CharField(verbose_name='会员', max_length=255)
    # 状态
    state = models.IntegerField(default=0)

    class Meta:
        db_table = 'role'


# 用户名
class User(models.Model):
    username = models.CharField(max_length=250)
    password = models.CharField(max_length=250)
    phone = models.CharField(max_length=250)
    role = models.ForeignKey(Role, on_delete=models.CASCADE, default='普通会员')
    money = models.CharField(verbose_name='钱', max_length=255, default=0)

    class Meta:
        db_table = 'user'


# 教练
class Coach(models.Model):
    name = models.CharField(max_length=255)
    age = models.IntegerField()
    gender = models.CharField(max_length=255)
    # 介绍
    introduce = models.CharField(max_length=255)
    # 状态  0 高级教练  1 普通教练
    level = models.IntegerField()

    class Meta:
        db_table = 'coach'


# 用户教练多对多
class Order(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    coach = models.ForeignKey(Coach, on_delete=models.CASCADE)
    # 状态
    state = models.IntegerField(default=0)
    # 花费前
    dazhe = models.IntegerField(default=0)  # 0不打折1打过折
    cost_money = models.FloatField(default=0.0)
    start_time = models.IntegerField(default=int(time.time()))
    end_time = models.IntegerField(default=0)
    ordernum = models.CharField(max_length=20, default='')

    class Meta:
        db_table = 'Order'
